/***************************************************
//Filename:     uscrn.h                             //
//Version:      V1.0                              //
//Released:		2008-09-19 15:00		          //
//Author:		Hua Weidong						  //
//Description:  for AWS-II.

//         READ ME
**2008-09-19 11:00
Creator: Hua Weidong
1.Version V1.0 is released.

****************************************************/

#ifndef	___USCRN_H___
#define	___USCRN_H___

#include    "qc.h"

#define	USCRN_WEIGH_PRECIPITATION_TOLERENCE	0.3	//0.3mm. A lower limit to the amount of precipitation that can be detected.
#define	USCRN_WEIGH_PRECIPITATION_EPS		0.2	//0.2mm or 0.3mm. A lower limit to the amount of precipitation that can be detected.
#define	USCRN_WEIGH_FREQUENCY_VARY			2.0	//Hz. For the 15 minute period
#define	USCRN_WEIGH_PMAX_5MINUTE			25.0	//mm, for the future 5-minute reporting interval
#define	USCRN_WEIGH_PMAX_15MINUTE			40.0	//mm, for the present 15-minute reporting interval
#define	USCRN_WEIGH_NAVG_5MINUTE			24	//times, the maximum number of pervious depths whose average determines the 
#define USCRN_WEIGH_NAVG_15MINUTE			8	//       depth reference level for each wire.

typedef struct _USCRN_WEIGH_PRECIPITATION{
	float	tolerance;	//unit: mm
	float	freqVary;	//unit: Hz
	float	eps;		//unit: mm
	float	pmax;
	float	plight;
	
	QC_DATA (*selectWeighPrecipitation)(struct _USCRN_WEIGH_PRECIPITATION *this,
		QC_DATA p1,QC_DATA p2,QC_DATA p3,
    	QC_DATA d1Prev,QC_DATA d1Now,QC_DATA d2Prev,QC_DATA d2Now,QC_DATA d3Prev,QC_DATA d3Now,
    	QC_DATA fMax1,QC_DATA fMin1,QC_DATA fMax2,QC_DATA fMin2,QC_DATA fMax3,QC_DATA fMin3,uint8_t *selected);
	} USCRN_WEIGH_PRECIPITATION;

extern USCRN_WEIGH_PRECIPITATION *uscrn_wp_Create(
	USCRN_WEIGH_PRECIPITATION *this,
	float tolerance,	//toerance between P1,P2,P3, 0.3mm at USCRN(is equal to EPS. We use 0.4mm	
	float	freqVary,	//frequency change, 2Hz at USCRN, we use -1Hz.
	float eps,  	//There is also a lower limit to the amount of precipitation that can be detected. 
					//The parameter EPS is used for this limit. Its value is 0.20 mm or 0.30mm.
					//We use 0.19mm for 0.2mm resolution or 0.1mm for 0.1 mm resolution
	float pmax, 	//Suggested values are 40.0mm for the present 15-minute interval and 25.0mm
				  	//for the future 5-minute reporting interval.
	float	plight	//0.3mm. at USCRN, this value is equal to EPS.
	);
	
extern QC_DATA uscrn_SelectAirTemperatureA(QC_DATA t1,QC_DATA t2,QC_DATA t3);
extern uint8_t uscrn_SelectAirTemperatureA_2(QC_DATA t1,QC_DATA t2,QC_DATA t3);
extern QC_DATA uscrn_SelectAirTemperatureB(QC_DATA t1,QC_DATA t2,QC_DATA t3,QC_DATA f1,QC_DATA f2,QC_DATA f3);
extern uint8_t uscrn_SelectAirTemperatureB_2(QC_DATA t1,QC_DATA t2,QC_DATA t3,QC_DATA f1,QC_DATA f2,QC_DATA f3);
extern uint8_t uscrn_SelectValidAirTemperature_2(QC_DATA t1,QC_DATA t2,QC_DATA t3);
extern int16_t uscrn_SelectPresentAirTemperature_2(QC_DATA t1,QC_DATA t2,QC_DATA t3);
extern uint8_t uscrn_SelectMEMSPressure(QC_DATA t1, QC_DATA t2, QC_DATA t3, float ptola1);
extern int16_t uscrn_SelectPresentMEMSPressure_2(QC_DATA t1,QC_DATA t2,QC_DATA t3);
extern uint8_t uscrn_SelectValidMEMSPressure_2(QC_DATA t1,QC_DATA t2,QC_DATA t3);
extern uint8_t uscrn_SelectDoubtfulMEMSPressure(QC_DATA t1,QC_DATA t2,QC_DATA t3);

extern QC_DATA uscrn_SelectFanSpeed(QC_DATA f1,QC_DATA f2,QC_DATA f3);

#endif
